package com.vineetmanohar.nitrogen;

import java.util.List;

/**
 * Represents a path that has been generated as a result of path generation.
 * Note that path generation does not care whether or not the file denoted by
 * the path exists or the contents of the file. This process does not try to
 * look for or open the file represented by this path.
 * 
 * This process is a pre-cursor to code generation which is a combination of
 * path generation and text generation.
 * 
 * This object captures 3 things: a) the value of the generated path b) the
 * context that was used to generate this path c) the input path that was used
 * to generate this path
 * 
 * 
 * @author vineetmanohar
 */
public class GeneratedPath {
	private String inputPath;

	public String getInputPath() {
		return inputPath;
	}

	private String generatedPath;

	public String getGeneratedPath() {
		return generatedPath;
	}

	private List<Model> pathGenerationContexts;

	public GeneratedPath(String inputPath, String generatedPath) {
		this.inputPath = inputPath;
		this.generatedPath = generatedPath;
		this.pathGenerationContexts = new ArrayModel();
	}

	public void addPathGenerationContext(ObjectModel objectModel) {
		this.pathGenerationContexts.add(objectModel);
	}

	/**
	 * @return the shortest depth context that matched or the first one if more
	 *         than one were the shorted depth
	 */
	public Model getPathGenerationContext() {
		int smallestDepth = Integer.MAX_VALUE;
		Model retVal = null;
		for (Model pathGenerationContext : pathGenerationContexts) {
			int depth = pathGenerationContext.getDepth();
			if (depth < smallestDepth) {
				retVal = pathGenerationContext;
				smallestDepth = depth;
			}
		}
		return retVal;
	}

	public List<Model> getPathGenerationContexts() {
		return pathGenerationContexts;
	}
}